package com.vanka.entity.account;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import lombok.Data;

// 用户信息表
@Data
public class UserEntity implements UserDetails {

	private Integer id;
	private String username;
	private String realname;
	private String password;
	private Date createDate;
	private Date lastLoginTime;
	private boolean enabled;//是否可用
	private boolean accountNonExpired;//是否过期
	private boolean accountNonLocked;//是否锁定
	private boolean credentialsNonExpired;//证书是否过期
	// 用户所有权限
	private List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();

	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}

	public void setUser(User u) {
		this.id = u.getId();
		this.username = u.getPhone();
		this.username = u.getName();
		this.password = u.getPassword();
		this.createDate = u.getCreateTime();
		this.lastLoginTime = u.getLastLoginTime();
		if(u.getStatus() == 0){
			this.enabled = false;
			this.accountNonLocked = true;
			this.accountNonLocked = true;
			this.credentialsNonExpired = true;
		}else if(u.getStatus() == 2){
			this.enabled = true;
			this.accountNonLocked = false;
			this.accountNonLocked = false;
			this.credentialsNonExpired = false;
		}else {
			this.enabled = false;
			this.accountNonLocked = true;
			this.accountNonLocked = true;
			this.credentialsNonExpired = true;
		}
	}
}
